package com.onesports.intelligent.k12.polarlight.controller.wx.student;

import com.onesports.intelligent.k12.polarlight.common.utils.ResultUtil;
import com.onesports.intelligent.k12.polarlight.constant.ApiPathConstants;
import com.onesports.intelligent.k12.polarlight.domain.dto.student.StudentSaveDTO;
import com.onesports.intelligent.k12.polarlight.domain.vo.student.StudentVO;
import com.onesports.intelligent.k12.polarlight.security.SecurityUtils;
import com.onesports.intelligent.k12.polarlight.service.student.MyStudentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author FPH
 * @since 2022年7月12日17:11:15
 */
@RestController
@Api(tags = "会员端-我的-我的学员")
@RequestMapping(ApiPathConstants.STUDENT)
@RequiredArgsConstructor
@PreAuthorize("hasAuthority('MINI_APP')")
public class MyStudentController {

    private final MyStudentService myStudentService;

    @GetMapping("list")
    @ApiOperation(value = "当前登录用户学生集合")
    public ResponseEntity<List<StudentVO>> list(){
        return ResultUtil.success(myStudentService.getStudentByUserId(SecurityUtils.getAccountId()));
    }

    @PostMapping("save")
    @ApiOperation(value = "保存学生")
    public ResponseEntity<String> saveStudent(@RequestBody @Valid StudentSaveDTO studentDTO){
        return myStudentService.saveStudent(studentDTO)?ResultUtil.success("操作成功"):ResultUtil.success("操作失败");
    }

    @PostMapping("remove")
    @ApiOperation("删除学生")
    public ResponseEntity<String> remove(String studentId){
        return myStudentService.removeStudent(studentId)?
                ResultUtil.success("删除成功"):ResultUtil.success("删除失败");
    }
}
